import crtkc from "./crtkc";
import { User } from "../scripts/UserManager";
import { UserData } from "../scripts/UserConst";
import { Tip } from "../scripts/TipManager";
import { Event } from "../scripts/EventManager";
import { default as GameEvent } from "../scripts/EventConst";
const {ccclass, property} = cc._decorator;

@ccclass
export default class CommonUse extends cc.Component {

    @property(cc.Label)
    lab_game: cc.Label = null;



    start () {
        //@ts-ignore
        let channel = window.__prv.getChannel();
        console.error("channel: ", channel);
        switch(channel){
            case 'ks':
                this.lab_game.string = '如花的奇葩事';
                break;
            case 'ks1':
                this.lab_game.string = '快救救孩子吧';
                break;
            case 'ks2':
                this.lab_game.string = '疯狂大作战';
                break;
            case 'ks3':
                this.lab_game.string = '全民求生';
                break;
        }

    }

    private close(){
        this.node.destroy();
    }

    private setCommonUse(){
        //@ts-ignore
        window.__prv.addCommonUse({
            sucCall: ()=>{
                console.error("设为常用成功");
                Tip.show("设为常用成功");
                //增加钥匙逻辑
                let key = User.get(UserData.KEY);
                User.set(UserData.KEY, key + 1);
                // Tip.show("钥匙+" + 1);
                Event.emit(GameEvent.KEY_EFFECT, true);
                crtkc.saveData('addCommon1', 1);
                this.node.destroy();
            },
            failCall: ()=>{
                console.error("设为常用失败");
                Tip.show("设为常用失败");
            }
        });

    }

}
